<template>
    <HeadImage :background="backPath" :height="'100vh'" id="decline">
        {{ disposition[0] }}
        <template v-slot:two>
            <p class="head">{{ disposition[1] }}</p>
        </template>
        <template v-slot:three>
            <div class="footer" @click="decline">
            </div>
        </template>
    </HeadImage>
    <div class="home_content" style="z-index: 8">
        <div class="home_left">
            <CarouselMap class="dis" :carouselMap="carouselMap"></CarouselMap>
            <BodyContent :class="{'global_font':$store.state.nowTime==='moon'}"></BodyContent>
        </div>
        <div class="home_right ">
            <div class="user_model user_models top"
                 :style="{'background':'rgba(255,255,255,0.6)'}">
                <div class="user "
                     :style="{'background':'url('+(user==null ? '/img/common/t0196dfad56317fe205.jpg':user.avatar )+')'}">
                    <div class="background_layer"  v-if="skeleton" >
                        <img :src="user==null ? '/img/common/NoLogin.png': user.avatar  "
                             alt=""
                             :class="{'user_img':true,'rotates_out':rotates_out}"
                             @mouseover="rotates_out_" @mouseout="rotates_out_">
                        <br>
                        <router-link :to="link">{{ user == null ? "登录/注册" : user.username }}</router-link>
                        <span class="partition"  v-show="user!=null"> | </span>
                        <router-link to="/login" v-show="user!=null" @click="logout">退出登录</router-link>
                        <p class="motto">{{ user == null ? "心中无女人，代码自然神！" : user.motto }}</p>
                        <Statistics :count="count"></Statistics>
                        <Contact :class="{'global_font':$store.state.nowTime==='moon'}" @infos="infos(sys)"></Contact>
                        <UserArticleContent
                                v-show="user!=null"
                                :essay="essayInfo"
                                :title_color="'#ef8a8a'"
                                :titleLi_color = "'#faf7f7'"
                                :title_img="'/img/common/mywenzhang.png'"
                                :content_img="'/img/common/lianjie.png'">我的作品
                        </UserArticleContent>
                    </div>
                    <div v-else class="box_circle">
                            <CircleLoading></CircleLoading>
                    </div>
                </div>

            </div>
            <div class="user_footer "
                 :class="{'global_font':$store.state.nowTime==='moon'}">
                <UserArticleContent
                        class="top like "
                        :essay="articleContent"
                        :title_color="'#e8b818'"
                        :titleLi_color = "'#8d8989'"
                        :title_img="'/img/common/feiji.png'"
                        :content_img="'/img/common/like.png'">猜你喜欢
                </UserArticleContent>
                <Countdown
                    :class="{'global_font':$store.state.nowTime==='moon'}"
                    class="top"
                ></Countdown>
                <SiteInformation
                        :class="{'global_footer':$store.state.nowTime==='moon'}"
                        :site_info="site_info">
                </SiteInformation>
            </div>


            <div class="user_model top"
                 style="width: 16vw ; padding:10px 10px;border-radius: 5px"
                 :class="{'sticky':stick,'disappear':disappear}"
                 v-show="stick">
                <div class="user"
                     :style="{'background':'url('+(user==null ? '/img/common/t0196dfad56317fe205.jpg':user.avatar )+')',}">
                    <div class="background_layer" v-if="skeleton">
                        <img :src="user==null ? '/img/common/NoLogin.png':user.avatar  " alt="" class="user_img">
                        <br>
                        <router-link :to="link">{{ user == null ? "登录/注册" : user.username }}</router-link>
                        <span style="color: #3586f1" v-show="user!=null"> | </span>
                        <router-link to="/login" v-show="user!=null" @click="logout">退出登录</router-link>
                        <p class="motto">{{ user == null ? "心中无女人，代码自然神！" : user.motto }}</p>
                        <Statistics :count="count"></Statistics>
                        <Contact @info="infos(sys)"></Contact>
                        <UserArticleContent
                            :essay="recentlyHot"
                            :title_color="'#ef8a8a'"
                            :titleLi_color = "'#faf7f7'"
                            :title_img="hot_title_background"
                            :content_img="'/img/common/lianjie.png'">我的作品
                        </UserArticleContent>
                    </div>
                    <div v-else class="box_circle">
                        <CircleLoading></CircleLoading>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <BulletinBoard @shutDown="shutDown" v-show="shutDown_" :board="bulletinBoard"></BulletinBoard>
    <PromptInformation :style="{'display':info!=='' ? 'flex':'none'}">{{info}}</PromptInformation>
</template>

<script>
import CarouselMap from "@/components/home/CarouselMap.vue";
import RecentArticles from "@/components/home/RecentArticles.vue";
import Contact from "@/components/home/Contact.vue";
import Statistics from "@/components/home/Statistics.vue";
import BodyContent from "@/components/home/BodyContent.vue";
import Countdown from "@/components/home/Countdown.vue";
import SiteInformation from "@/components/PublicComponents/SiteInformation.vue";
import HeadImage from "@/components/PublicComponents/HeadImage.vue";
import api from "@/api";
import UserArticleTitle from "@/components/home/UserArticleTitle.vue";
import UserArticleContent from "@/components/home/UserArticleContent.vue";
import BulletinBoard from "@/components/home/BulletinBoard.vue";
import PromptInformation from "@/components/PublicComponents/PromptInformation.vue";
import CircleLoading from "@/components/PublicComponents/CircleLoading.vue";
import axios from "@/utils/request";

export default {
    name: "home",
    components: {
        CircleLoading,
        PromptInformation,
        BulletinBoard,
        UserArticleContent,
        UserArticleTitle,
        HeadImage,
        CarouselMap,
        RecentArticles,
        Contact,
        Statistics,
        BodyContent,
        Countdown,
        SiteInformation,

    },
    props: ['time'],
    data() {
        return {
            rotates_out:true,
            sys:"系统正在升级！",
            backPath: "/img/common/t0126965e612a7835ac.jpg",
            user_img: "/img/common/微信图片_20230610111608.jpg",
            count: {
                body_count: "",
                label_count: "",
                comments_count: "",
            },
            essays: "",
            user: {
                avatar: "",
                motto: "",
                username: "",
            },
            stick: false,
            fixed: false,
            recentlyHot: [],
            disappear: false,
            unfold: false,
            index: 0,
            link: "",
            essayInfo: [],
            logoutInfo: {
                id: "",
                token: "",
            },
            hot_title_background: "/img/common/hot.png",
            My_title_background: " /img/common/mywenzhang.png",
            path: [], //用户使用的浏览器版本型号
            disposition: "",
            carouselMap: "",
            site_info: "",
            shutDown_: false,

            index_info:true,
            pas:false,
            captcha:true,
            info:"",
            time_info:"",
            bulletinBoard:"",
            skeleton:false,
            articleContent:[],
        }
    },
    mounted() {
        //获取网站配置是数据
        let writing = [{options:"",content:""}];
        setTimeout(()=>{
            writing = JSON.parse(window.localStorage.getItem("DataContent"));
            this.site_info=writing[9].content.split("|||||");
            this.disposition = writing[2].content.split("|||||");
            this.carouselMap = writing[0].content.split(',');
            this.backPath = writing[1].content;
        },200)
        this.user = JSON.parse(window.localStorage.getItem("user"));
        if (this.user) {
             api.saveUserFives(this.user.uid).then((res) => {
                this.essayInfo = res.data.data ? res.data.data : [];
            })
        }
        api.getGuessYouLike().then((res) => {
            this.articleContent = res.data.data;
        })
        let ts = window.localStorage.getItem("nowTime")
        if (ts !== "") {
            this.$store.commit("nowTimeStatue", ts);
        }
        //取出用户的基本信息
        if (this.user) {
            this.link = "/personalInformation";
        } else {
            this.link = "/login";
        }


        window.addEventListener('scroll', this.handleScrollx, false);


       setTimeout(()=>{
           let bord =  JSON.parse(window.localStorage.getItem("BulletinBoard"))
           if(bord){
               api.getAnnouncement(1).then((res)=>{
                 if(res.data.data.length>0) {
                     this.bulletinBoard = res.data.data[0];
                     if (bord.id !== res.data.data[0].id && this.bulletinBoard.content !== '') {
                         this.shutDown_ = true;
                         window.localStorage.setItem("BulletinBoard", JSON.stringify({
                             id: this.bulletinBoard.id,
                             checked_: 0
                         }));
                     } else if (bord.checked_ === 0) {
                         window.localStorage.setItem("BulletinBoard", JSON.stringify({
                             id: this.bulletinBoard.id,
                             checked_: 0
                         }));
                         this.shutDown_ = true;
                     } else {
                         this.shutDown_ = false;

                     }
                 }
               })
           }else{
               api.getAnnouncement(1).then((res)=>{
                   if( this.bulletinBoard.content !== '') {
                       if( res.data.data.length>0){
                           window.localStorage.setItem("BulletinBoard",
                               JSON.stringify({id: res.data.data[0].id,checked_:0}));
                           this.bulletinBoard = res.data.data[0];
                           this.shutDown_ = true;
                       }
                   }
               })
           }
       },200)

       api.getRecentlyHot().then(res=>{
           this.recentlyHot = res.data.data;
       })


        this.platform();
    },
    watch:{
        user(newValue,oldValue){
               setTimeout(()=>{
                   this.skeleton = true
               },100)
        }
    },
    methods: {
        platform(){
            //
            //获取浏览器用户使用的浏览器型号系统信息
            const userAgent = navigator.userAgent;
            if (userAgent.indexOf("Windows") !== -1) this.path.push("/img/common/win.png");
            else if (userAgent.indexOf("Mac") !== -1) this.path.push("/img/common/macOS.png");
            else if (userAgent.indexOf("X11") !== -1) this.path.push("UNIX");
            else if (userAgent.indexOf("Linux") !== -1)
                this.path.push("/img/common/linux.png");
            else
                this.path.push("Other");
            let mb = this.myBrowser();
            if ("IE" == mb) {
                this.path.push("/img/common/ie.png");
            }
            if ("FF" == mb) {
                this.path.push("Other");
            }
            if ("Chrome" == mb) {
                this.path.push("/img/common/chrome.png");
            }
            if ("Opera" == mb) {
                this.path.push("Other");
            }
            if ("Safari" == mb) {
                this.path.push("/img/common/safari.png");
            }
            window.localStorage.setItem("platform", this.path);
        },
        myBrowser() {
            let userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
            // console.log(userAgent)
            let isOpera = userAgent.indexOf("Opera") > -1;
            if (isOpera) {
                return "Opera"
            } //判断是否Opera浏览器
            if (userAgent.indexOf("Firefox") > -1) {
                return "FF";
            } //判断是否Firefox浏览器
            if (userAgent.indexOf("Chrome") > -1) {
                return "Chrome";
            }
            if (userAgent.indexOf("Safari") > -1) {
                return "Safari";
            } //判断是否Safari浏览器
            if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
                return "IE";
            } //判断是否IE浏览器
        },
        rotates_out_(){
          this.rotates_out_ = !this.rotates_out_
        },
        shutDown() {
            this.shutDown_ = false;
        },
        decline() {
            let decline = document.querySelector("#decline");
            let html = document.documentElement;
            html.scrollTo({top: decline.clientHeight - 35, behavior: 'smooth'})

        },
        logout() {
            let _this = this;
            //退出登录前的操作
            api.logout().then((res) => {
                if (res.data.code === 200) {
                    window.localStorage.clear();
                    _this.$router.push("/login")
                }
                alert(res.data.msg);
            });

        },

        handleScrollx() {
            let m = document.querySelector(".top");
            let f = document.querySelector(".user_footer");
            let c = document.querySelector(".home_content")
            if (m != null && f != null && c != null) {
                if ((window.pageYOffset >= (m.offsetHeight + f.offsetHeight + c.offsetTop)) && this.index === 0) {
                    this.stick = true;
                    this.disappear = false;
                    this.unfold = false;
                    this.index = 1;
                } else if (!(window.pageYOffset >= (m.offsetHeight + f.offsetHeight + c.offsetTop)) && this.index === 1) {
                    this.disappear = true;
                    this.index = 0;
                    setTimeout(() => {
                        this.stick = false;
                    }, 100)
                }
            }
        },


        infos(str) {
            this.info = "";
            this.info = str;
            if (this.index_info) {
                this.index_info = false;
                this.pas = !this.pas;
                clearInterval(this.time_info);
                this.time_info = setInterval(() => {
                    this.info = "";
                    this.index_info = true;
                }, 4000)
            }
        },
    },
    beforeDestroy: function () {
        window.removeEventListener('scroll', this.handleScrollx, false);
    },

}
</script>

<style scoped>
.box_circle{
    background: #f6f7f8;
    width: 100%;
    height: 100% ;
    min-height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.background_layer{
    background: rgba(17, 17, 17, 0.5);
}
.like {
    box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.top {
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.6) !important;
}

@keyframes gradients {
    0% {
        opacity: 0.1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}

.home_left {
    margin-bottom: 50px;
}

.home_content {
    display: flex;
    justify-content: center;
    opacity: 1;
    border-radius: 5px;
}

@keyframes gradient {
    0% {
        opacity: 0;
        margin-top: 10vh;
    }
    90%{
        opacity: 1;
    }
    100% {
        opacity: 1;
        margin-top: 0;
    }
}

.home_right {
    width: 270px;
    margin-left: 1rem;
    transition: all .5s;
    opacity: 0;
    animation: gradient .9s .5s forwards;
}

.home_right ul li {
    list-style: none;
    width: 100%;
    font-size: 1vw;
}

.user {
    margin-left: 0;
    min-width: 15rem;
    text-align: center;
    background-repeat: no-repeat !important;
    background-position: top center !important;
    background-size: cover !important;
}

.user .user_img {
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 50%;
    box-shadow: 0 1px 1px 0 rgba(248, 245, 245, 1), 0 6px 20px 0 rgba(253, 252, 252, 0.9);
    margin-top: 10vh;
    min-height: 50px;
    object-fit: cover;
    background: rgba(180, 169, 169, 0.94);
}

.user:hover .user_img{
    animation:rotates_hover  1.5s ease-in-out 0s 1 forwards;
}


.home_right .user a {
    color: #f9f9fa;
}

.home_right .user a:hover {
    text-decoration: underline;
}

@keyframes rotates_hover {
    0% {
        transform: rotateX(0deg);
    }
    100% {
        transform: rotateX(360deg);
    }
}
.rotates_out{
    animation:rotates_out  1.5s ease-in-out 0s 1 forwards;
}
@keyframes rotates_out {
    0% {
        transform: rotateX(0deg);
    }
    100% {
        transform: rotateX(-360deg);
    }
}

.motto {
    font-size: 14px;
    margin-top: 5px;
    color: #ee4f4f;
    font-weight: bolder;
}

.sticky {
    position: fixed !important;
    width: 17vw;
    min-width: 16rem;
    top: 50px;
    transition: all .5s;
    animation: right 0.5s ease-in-out 0s 1 forwards;
}

@keyframes right {
    0% {
        transform: scale(0);
    }
    70% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

.disappear {
    animation: disappear 0.1s ease-in-out 0s 1 forwards;
}

@keyframes disappear {
    0% {
        transform: scaleY(0.5);
    }
    100% {
        transform: scaleY(0);
    }
}


.dis {
    display: block;
    margin-bottom: 15px;
}


.head {
    position: relative;
    overflow: hidden;
    width: 0;
    font-size: 1.3rem;
    line-height: 34px;
    white-space: nowrap;
    text-align: center;
    margin: auto;
    text-shadow: 3px 3px 3px #383636;
    margin-top: 30px;
    animation: width 2s steps(14) forwards;
}

@keyframes width {
    0% {
        width: 0;
    }
    100% {
        width: 18em;
    }
}



.head img {
    margin-left: 5px;
    width: 25px
}

.user_model {
    color: white;
    background: transparent;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.partition{
    color: white;
}
.footer {
    position: absolute;
    cursor: pointer;
    bottom: 6%;
    left: 50%;
    border: 0;
    width: 25px;
    height: 25px;
    border-right: 5px solid #8f8c8c;
    border-bottom: 5px solid #8f8c8c;
    border-radius: 3px;
    transform: translateX(-50%) rotate(45deg);
    animation: footer 1.5s ease-out 0s infinite forwards;
}

@keyframes footer {
    0% {
        bottom: 8%;
    }
    60% {
        opacity: .9;
        bottom: 5%;
    }
    100% {
        opacity: 1;
        bottom: 8%;
    }
}

@media (min-width: 0px) and (max-width: 900px) {
    .home_right {
        display: none;
    }

}



</style>